#!/usr/bin/ruby
# -*- ruby -*-
#
# http://programmingpraxis.com/2014/02/21/anagrams-within-words/

require 'pp'

def freq(word)
  return word.split(//).inject({}) do |res, val|
    res[val] ||= 0
    res[val] += 1

    res
  end
end

def anagram_within_word(first, second)
  first_set = freq(first)

  (0).upto(second.length - first.length) do |i|
    second_set = freq(second.slice(i, first.length))

    return true if first_set == second_set
  end

  return false
end

first, second = ARGV

puts anagram_within_word(first, second)
